/**
 * 
 */
package org.leumasjaffe.util;

import org.eclipse.jdt.annotation.NonNull;

/**
 * @author leumasjaffe
 *
 */
public class Stack<T extends Stackable> implements Stackable {
	final T base;
	final T top;
	
	public Stack(@NonNull T base, @NonNull T top) {
		this.base = base;
		this.top = top;
	}
	
	@SuppressWarnings("null")
	public @NonNull T getBase() {
		return this.base;
	}
	
	@SuppressWarnings("null")
	public @NonNull T getTop() {
		return this.top;
	}
	
	public static @NonNull <T extends Stackable> Stackable stack(T bottom, T top) {
		if (bottom == null) {
			if (top != null)
				return top;
		}
		else if (top == null)
			return bottom;
		else
			return new Stack<T>(bottom, top);
		throw new IllegalArgumentException("Passing Two Null arguments to stack() is not supported");
	}

	public static @NonNull <T extends Stackable> T unstack(Stack<T> stack) {
		return stack.getBase();
	}

}
